/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Users;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author owtee
 */
@Stateless
public class UsersFacade extends AbstractFacade<Users> {

    @PersistenceContext(unitName = "MSGPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsersFacade() {
        super(Users.class);
    }

    public List<Users> findByEmpName(String empName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT u FROM Users u WHERE (u.empFirstName LIKE :empName OR u.empLastName LIKE :empName)")
                .setParameter("empName", empName)
                .getResultList();
    }

    public List<Users> findByEmpName(int start, int end, String empName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT u FROM Users u WHERE (u.empFirstName LIKE :empName OR u.empLastName LIKE :empName)")
                .setFirstResult(start)
                .setMaxResults(end)
                .setParameter("empName", empName)
                .getResultList();
    }

    public List<Users> findByUserAndPwd(String userId, String userPwd) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT u FROM Users u WHERE u.userId = :userId AND u.userPwd = :userPwd")
                .setParameter("userId", userId)
                .setParameter("userPwd", userPwd)
                .getResultList();
    }
}
